import fs from 'node:fs';

function generate(dirPath: string, path?: string) {
    const scanResult = fs.readdirSync(dirPath, 'utf8');
    const fileNames = scanResult.filter(fileName => {
        if (fileName === 'index.ts') return false;
        return fileName.endsWith('.ts');
    });
    const data = fileNames.map(fileName => `export * from './${fileName.slice(0, -3)}';`).join('\n');
    if (!path) {
        path = dirPath + "\\" + 'index.ts';
    }
    return fs.writeFileSync(path, data, { flag: 'w' });
}

export {
    generate
}